<template>
  <el-card class="content">
    <el-row>
      <el-col :span="4">
        <span>巡查点：</span>
        <el-input
          placeholder="请输入项目名称"
          size="mini"
          style="width: 200px"
          v-model="query.position"
          clearable
        ></el-input>
      </el-col>
      <el-col :span="4">
        <span>班别：</span>
        <el-select
          placeholder="请选择班别"
          size="mini"
          style="width: 200px"
          v-model="query.shiftLevel"
          clearable
          ><el-option
            v-for="item in shiftLevelList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option
        ></el-select>
      </el-col>
      <el-col :span="4">
        <el-button
          class="black-button"
          size="mini"
          type="primary"
          @click="getSearch"
          >查询</el-button
        >
      </el-col>
    </el-row>
    <el-table
      :data="handoverReportList"
      stripe
      size="small"
      :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }"
      class="el-table-box"
    >
      <el-table-column
        prop="position"
        label="巡查点"
        align="center"
        width="150px"
      >
      </el-table-column>
      <el-table-column prop="shiftLevel" label="班别">
        <template slot-scope="scope">
          <span v-if="scope.row.shiftLevel == 1">早</span>
          <span v-if="scope.row.shiftLevel == 2">中</span>
          <span v-if="scope.row.shiftLevel == 3">晚</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="pipeline"
        label="放矿管道"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="branchPipe"
        label="放矿支管"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="oreDrawingStartTime"
        label="放矿开始时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="oreDrawingEndTime"
        label="放矿结束时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="portalDrainage"
        label="洞口排水情况"
        align="center"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.portalDrainage == 0">清水</span>
          <span v-if="scope.row.portalDrainage == 1">浑水</span>
        </template>
      </el-table-column>
      <el-table-column prop="seepage" label="坝脚渗流情况" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.seepage == 0">清水</span>
          <span v-if="scope.row.seepage == 1">浑水</span>
        </template>
      </el-table-column>
      <el-table-column label="放矿存在问题">
        <template slot-scope="scope">
          <el-button
            type="text"
            v-if="scope.row.oreDrawingStatus == 0"
            size="small"
            >正常</el-button
          >
          <el-button
            type="danger"
            v-if="scope.row.oreDrawingStatus == 1"
            size="small"
            @click="updateInfo(scope.row)"
            >异常</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-row type="flex" justify="end">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.page"
        :page-sizes="[10, 15]"
        :page-size="query.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-row>
    <!-- 方矿存在异常时的弹窗 -->
    <el-dialog title="放矿存在异常时" :visible.sync="dialogVisible" width="30%">
      <el-table
        :data="oreDrawingList"
        stripe
        style="width: 100%; display: block; max-height: 60vh; overflow-y: auto"
      >
        <el-table-column label="异常图片">
          <template slot-scope="scope">
            <el-image
              v-if="oreDrawingLenght !== 1"
              :src="imgUrl + scope.row.oreDrawingImage.split(',')[0]"
              class="bigIntelligent"
              :preview-src-list="oreDrawingImgList"
              @click="dialogVisible=false"
            ></el-image>
            <el-image
              v-if="oreDrawingLenght == 1"
              :src="imgUrl + scope.row.oreDrawingImage"
              class="bigIntelligent"
              :preview-src-list="oreDrawingImgList"
              @click="dialogVisible=false"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="oreDrawingDesc" label="异常描述">
          <template slot-scope="scope">
            <span>{{ scope.row.oreDrawingDesc }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </el-card>
</template>
<script>
import { getSafetyInspectorListByPage, imgUrl } from "../../../api/api";
export default {
  name: "ShiftTurnover",
  data() {
    return {
      query: {
        page: 1,
        pagesize: 10,
        position: "",
        shiftLevel: null,
      },
      imgUrl,
      total: null,
      // 存放所有交接班信息列表数据
      handoverReportList: [],
      // 班别列表
      shiftLevelList: [
        { id: 1, name: "早" },
        { id: 2, name: "中" },
        { id: 3, name: "晚" },
      ],
      // 洞口排水情况列表
      portalDrainageList: [
        { id: 0, name: "清水" },
        { id: 1, name: "浑水" },
      ],
      // 坝脚渗流情况列表
      seepageList: [
        { id: 0, name: "清水" },
        { id: 1, name: "浑水" },
      ],
      dialogVisible: false,
      oreDrawingList: [],
      oreDrawingLenght: null,
      oreDrawingImgList: [],
    };
  },
  created() {
    this.getHandoverReportList();
  },
  methods: {
    async getHandoverReportList() {
      const res = await getSafetyInspectorListByPage({
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        inspectionType: "9",
        position: this.query.position,
        shiftLevel: this.query.shiftLevel,
      });
      console.log(res);
      if (res.resultCode == "200") {
        this.handoverReportList = res.parameter.list;
        this.total = res.parameter.total;
      } else {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.handoverReportList = [];
      }
    },
    async getSearch() {
      const res = await getSafetyInspectorListByPage({
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        inspectionType: "9",
        position: this.query.position,
        shiftLevel: this.query.shiftLevel,
      });
      if (res.resultCode == "200") {
        this.$message({
          type: "success",
          message: "成功查询数据",
          offset: 400,
          duration: 1000,
        });
        this.handoverReportList = res.parameter.list;
        this.total = res.parameter.total;
      }
      if (res.resultCode == "204") {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.handoverReportList = [];
      }
      this.total = res.parameter.total;
    },
    // 监听 pagesize 改变的事件
    handleSizeChange(val) {
      this.query.pagesize = val;
      this.getHandoverReportList();
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(val) {
      this.query.page = val;
      this.getHandoverReportList();
    },
    setDialogWidth() {
      var val = document.body.clientWidth;
      const def = 750; // 默认宽度
      if (val < def) {
        this.dialogWidth = "100%";
      } else {
        this.dialogWidth = def + "px";
      }
    },
    updateInfo(row) {
      console.log(row);
      this.oreDrawingList = [];
      this.oreDrawingImgList = [];
      let obj = {};
      obj["oreDrawingDesc"] = row.oreDrawingDesc;
      obj["oreDrawingImage"] = row.oreDrawingImage;
      this.oreDrawingList.push(obj);
      console.log(this.oreDrawingList);
      for (let i = 0; i < this.oreDrawingList.length; i++) {
        let ele = this.oreDrawingList[i];
        if (this.oreDrawingList[i].oreDrawingImage.indexOf(",") !== -1) {
          let ele = this.oreDrawingList[i].oreDrawingImage.split(",");
          this.oreDrawingLenght = ele.length;
          for (let j = 0; j < ele.length; j++) {
            let e = ele[j];
            this.oreDrawingImgList.push(imgUrl + e);
          }
        } else {
          this.oreDrawingImgList.push(
            imgUrl + this.oreDrawingList[i].oreDrawingImage
          );
        }
      }
      this.dialogVisible = true;
    },
  },
};
</script>
<style scoped>
.content {
  margin-right: 5px;
  height: 87vh;
}
.list {
  height: 83vh;
}
.el-table-box {
  margin-top: 20px;
  margin-bottom: 20px;
  display: block;
  height: 73vh;
  overflow-y: auto;
}
.el-table::before {
  z-index: inherit;
}
.bigIntelligent {
  max-height: 200px;
  max-width: 200px;
  object-fit: contain;
  z-index: 10000;
}
</style>